package com.eflow.model.flowable.converter;

import cn.hutool.core.bean.BeanUtil;
import com.eflow.model.domain.EflowUser;
import com.eflow.model.e.BpmConst;
import com.eflow.model.flowable.entity.ScriptEntity;
import com.eflow.model.flowable.model.UserElement;
import com.eflow.model.flowable.model.e.UserTypeEnum;
import com.eflow.model.groovy.GroovyScriptEngine;
import com.eflow.model.service.IEflowUserService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 获取流程发起人
 * @author hui se
 * @description
 * @create 2021-03-05 18:21
 **/
@Component
public class UserStartUserConverter extends BaseUserListConverter  {

    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private IEflowUserService eflowUserService;

    @Override
     List<EflowUser> list(UserElement userElement, String loginUser, ProcessDefinition processDefinition, String processInstanceId, String activityId, Map<String,Object> var) {
     List<EflowUser> userList = new ArrayList<>();
        Object initiator = var.get(BpmConst.FLOW_SUBMIT_TASK_VAL);
        if(initiator!=null){
            EflowUser eflowUser = eflowUserService.selectUserByUserId(initiator.toString());
            if(eflowUser!=null){
                userList.add(eflowUser);
            }
        }
        return userList;
    }
    @Override
    UserTypeEnum getUserType() {
        return UserTypeEnum.START_USER;
    }
}
